﻿namespace LogicStudio.Framework.UI.Comandos
{
    using System;
    using System.Windows.Controls;
    using System.Windows.Input;

    public class ComandoCerrarVentana : ICommand
    {
        #region Constructor
        /// <summary>
        /// Comando que se decencadena al cerrar la ventana.
        /// </summary>
        public ComandoCerrarVentana()
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, null);
            }
        }

        #endregion

        #region Eventos

        public event EventHandler CanExecuteChanged;

        #endregion

        #region Métodos Públicos

        public bool CanExecute(object parameter)
        {
            return true;
        }

        /// <summary>
        /// Cierra una ventana
        /// </summary>
        /// <param name="parameter">Parametro que indica la ventana a cerrarce</param>
        public void Execute(object parameter)
        {
            if (parameter != null && parameter.GetType().BaseType == typeof(ChildWindow))
            {
                var ventana = (ChildWindow)parameter;
                ventana.DialogResult = false;
            }
        }

        #endregion
    }
}